<?php
class FeedbackService extends My_Service
{   
    public function check()
    {
    	//validate Title
		$titleVald = new Zend_Validate_StringLength(5, 255);
		if(!$titleVald->isValid($_POST['title']))
		{
			$this->_errorList["title"] = My_Message::get("S002|Title|10|255");
			return false;
		}
		
    	//validate content
		$bodyVald = new Zend_Validate_StringLength(10);
		if(!$bodyVald->isValid($_POST['content']))
		{
			$this->_errorList["content"] = My_Message::get("S003|Content|10");
		}
		
   		//validate username length
		$userNameValdLength = new Zend_Validate_StringLength(5, 50);
		if(!$userNameValdLength->isValid($_POST['yourName']))
		{
			$this->_errorList['yourName'] = My_Message::get("S002|Your name|5|50");
		}
		else
		{
			//validate username string
			$userNameValdAlnum = new Zend_Validate_Alnum();
			if(!$userNameValdAlnum->isValid($_POST['yourName']))
			{
				$this->_errorList['yourName'] = My_Message::get("S006|Your name");
			}
		}
		
    	//validate email
		$emailVald = new Zend_Validate_EmailAddress();
		if(!$emailVald->isValid($_POST['yourEmail']))
		{
			$this->_errorList['yourEmail'] = My_Message::get("S007|Your email");
			return false;
		}
				
		if(empty($this->_errorList) == false)
		{
			return false;
		}
		return true;
    }
    
	public function bind()
	{
		$feedback = new FeedbackDTO( );
		if(!empty($_POST['feedbackId']))//case edit
		{
			$feedback = $this->load($_POST['feedbackId']);
		}
		
		$feedback->title = $_POST['title'];
		$feedback->content = $_POST['content'];
		$feedback->yourName = $_POST['yourName'];
		$feedback->yourEmail = $_POST['yourEmail'];
		
		return $feedback;
	}
    
    public function store()
    {
    	//check input data
    	if(!$this->check())
    	{
			return false;
    	}
    	
    	//bind data
    	$feedback = $this->bind();
    	
    	//save data
    	$this->save($feedback);
    	return true;
    }
    
}
?>